package com.generalsentiment.evaluation

import java.io.File
import java.io.PrintWriter
import scala.io.Source

// This class of tests compare how well a test sentiment analysis algorithm ranks entities
// compared to some gold standard ranking
class RankTest(sourceFile: File) extends SentimentTest {

  // read in the file and load the true rankings
  private val inputLines = Source.fromFile(sourceFile).getLines
  private val date: SentimentTest.Date = Integer.parseInt(inputLines.next.trim())
  private val goldRanks = inputLines.map(new RankExample(_))

  def makeQueries(destination: File): Unit = {
    val output = new PrintWriter(new File(destination,sourceFile.getName()))
    output.println(date)
    goldRanks.foreach(_.makeQueries(output))
    output.close()
  }
}

class RankExample(lineToParse: String) {
  private val tokens = lineToParse.split("\t")
  private val rank: Int = Integer.parseInt(tokens(0))
  private val entity: String = tokens(1)

  def makeQueries(output: PrintWriter): Unit = {
    output.println(entity)
  }
}
